package com.gzdh.dishrecognition.util;

import com.dhkj.web.bean.Bmzl;
import com.dhkj.web.bean.MacMainpSbruanDinner;
import com.gzdh.dishrecognition.AppContext;
import com.gzdh.dishrecognition.entity.BmcmEntity;
import com.gzdh.dishrecognition.entity.BmzlEntity;
import com.gzdh.dishrecognition.entity.MacMainpSbruanDinnerEntity;
import com.gzdh.dishrecognition.entity.WeekMenuBakEntity;
import com.gzdh.dishrecognition.model.WeekMenuBakModel;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class ProductSUtils {

    public static List<WeekMenuBakModel> getWeekMenuBakModel(List<BmzlEntity> bmzlList,
                                                             List<WeekMenuBakEntity> weekMenuBakEntityList,
                                                             String bmcmId) {
        List<WeekMenuBakModel> weekMenuBakModelList = new ArrayList<>();

        for (BmzlEntity goo : bmzlList) {
            List<WeekMenuBakEntity> weekMenuBakEntityList1 = weekMenuBakEntityList.stream()
                    .filter(weekMenuBakEntity -> weekMenuBakEntity.getZl().trim().equals(goo.getBm().trim())).collect(Collectors.toList());
            List<WeekMenuBakModel.Product> productList = new ArrayList<>();
            for (WeekMenuBakEntity goo1 : weekMenuBakEntityList1) {
                WeekMenuBakModel.Product product = new WeekMenuBakModel.Product();
                product.setBm(goo1.getBm().trim());
                product.setName(goo1.getName());
                product.setPrice(goo1.getPrice());
                product.setZl(goo1.getZl());
                product.setAddr(goo1.getAddr());
                product.setDinner(goo1.getDinner());
                productList.add(product);
            }
            if (productList.size() > 0) {
                WeekMenuBakModel weekMenuBakModel = new WeekMenuBakModel();
                weekMenuBakModel.setBmcm(bmcmId);
                weekMenuBakModel.setBm(goo.getBm().trim());
                weekMenuBakModel.setName(goo.getName());
                weekMenuBakModel.setProductList(productList);
                weekMenuBakModelList.add(weekMenuBakModel);
            }
        }
        return weekMenuBakModelList;
    }


    public static void setSbruanDinnerName(List<MacMainpSbruanDinnerEntity> macMainpSbruanDinnerList) {

        List<BmcmEntity> bmcmEntityList =
                AppContext.getInstance().getDaoSession().getBmcmEntityDao().loadAll();
        for (MacMainpSbruanDinnerEntity goo : macMainpSbruanDinnerList) {
            BmcmEntity bmcmEntity = bmcmEntityList.stream().filter(bmcmEntity1 -> bmcmEntity1.getBm().trim().equals(goo.getDinner().trim()))
                    .findFirst().orElse(null);
            if (bmcmEntity != null) {
                goo.setDinnerName(bmcmEntity.getName());
            } else {
                goo.setDinnerName("");
            }
        }
    }
}
